import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        list: [{ title: 'text1', id: 1 }, { title: 'text2', id: 2 }, { title: 'text3', id: 3 }, { title: 'text4', id: 4 }, { title: 'text5', id: 5 }],
        isShap: "",//控制横竖
        isBig: "",//没用
        textValue:"",//输入框的值
    },
    getters: {
            search(state){
                return state.list.filter(item=>item.title.includes(state.textValue))
            }
    },
    mutations: {
        newList(state, payload) {
            state.list = payload
        },
        newTape(state, payload) {
            state.isShap = payload
        },
        newBig(state,payload){
            if(payload==true){
                state.list=state.list.sort((a, b) => b.id - a.id)
            } else {
                state.list=state.list.sort((a, b) => a.id - b.id)
            }
        },
        add(state,payload){
            state.list.push(payload)
        },
    },
    actions: {},
    modules: {}
})
